﻿
Partial Class WebForm_ManageVolunteer_SearchVolunteer
    Inherits MyUserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ScriptManager.GetCurrent(Me.Page).RegisterPostBackControl(Me.btnExportVolunteer)

        If Not IsPostBack Then
            Me.BindDDLVOrganizationID()
            Me.BindDDLVolunteerType(Me.ddlVolunteerType)
            Me.ddlVolunteerType.Items.Insert(0, MyObj.GetDDLSelectAllItem())
            Me.BindDDLGroupName(IIf(Me.ddlVOrganizationID.SelectedValue <> "", Me.ddlVOrganizationID.SelectedValue, 0))
            RaiseEvent Loaded(Me, New EventArgs)

        End If

        If Me.CanAdmin = False Then
           
            If Me.ddlVOrganizationID.SelectedValue <> "" AndAlso (CanEdit = True Or CanQuery = True) Then
                ' MyObj.WriteErrorLog(MyObj.VolunteerBasicDataIsCheck(ddlVOrganizationID.SelectedValue))
                If MyObj.VolunteerBasicDataIsCheck(ddlVOrganizationID.SelectedValue) = True Then
                    btnShowPerson.Visible = False
                    IsLock = True
                Else
                    btnShowPerson.Visible = True
                    IsLock = False
                End If
            Else
                btnShowPerson.Visible = True
                IsLock = False

            End If

        End If
    End Sub


    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
       If e.CommandName = "DeleteVolunteer" Then '退出志工
            Dim row As GridViewRow = TryCast(TryCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            Dim key As DataKey = Me.gv.DataKeys(row.RowIndex)

            Dim dat As New clsData
            Dim sql As New MyStringBuilder

            Using scope As New Transactions.TransactionScope
                sql.Length = 0
                sql.AppendFormat("DELETE VOrganizationMapping ")
                sql.AppendFormat("WHERE VolunteerID='{0}' and VOrganizationID='{1}'; ", key.Values(0), key.Values(1))

                dat.AccData(sql)
                Me.SaveData(row.RowIndex, "Volunteer")

                scope.Complete()
            End Using

            Me.BindGV()
            Me.ChangeRecordControl1.InitAndShow()
            Me.RecordVolunteerID = key.Values(0).ToString()
            Me.RecordVOrganizationID = key.Values(1).ToString()
            Me.RecordType = "QuitVOrganizaiton"
        End If


    End Sub

    Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
      

            Dim ddl As DropDownList = TryCast(e.Row.FindControl("ddlVolunteerType"), DropDownList)

            Me.BindDDLVolunteerType(ddl)

            If Not TypeOf DataBinder.Eval(TryCast(ddl.NamingContainer, GridViewRow).DataItem, "Source") Is DBNull Then
                ddl.SelectedValue = DataBinder.Eval(TryCast(ddl.NamingContainer, GridViewRow).DataItem, "Source")
            End If
        End If
    End Sub

    Protected Sub gv_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv.SelectedIndexChanged
        RaiseEvent SelectedIndexChanged(Me, New EventArgs)
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click

     

        If ddlVOrganizationID.SelectedValue <> "" Then
            Me.BindDDLGroupName(ddlVOrganizationID.SelectedValue)
        Else
            MyObj.ShowMessage("未選擇志工隊")
            Return
        End If

        Me.BindGV()
    End Sub

    Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
        If Me.SaveData(e.RowIndex) = True Then
            MyObj.ShowMessage("更新完成")
            Me.BindGV()
        End If
    End Sub

    '加入志工開窗取值-Volunteer
    Protected Sub btnShowPerson_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowPerson.Click

        If Me.ddlVOrganizationID.SelectedValue = "" Then
            MyObj.ShowMessage("未選擇志工隊")
        Else
            SearchRegionVolunteerControl1.InitDataAndShow(ddlVOrganizationID.SelectedValue)
        End If

    End Sub

    '加入志工開窗取值回來-Volunteer
    Protected Sub SearchRegionVolunteerControl1_OK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchRegionVolunteerControl1.OK_Click

        Me.SavePerson()
        Me.BindGV()

    End Sub

 

    Protected Sub gv_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gv.RowEditing
        Dim key As DataKey = Me.gv.DataKeys(e.NewEditIndex)
        Me.VolunteerID = key.Value
        RaiseEvent SelectedIndexChanged(Me, New EventArgs)
    End Sub

    Protected Sub gv_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gv.Sorting
        Me.BindGV()
    End Sub

    Protected Sub btnExportVolunteer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportVolunteer.Click
        Me.Export()
    End Sub

    Protected Sub ChangeRecordControl1_OK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ChangeRecordControl1.OK_Click
        MyObj.ChangeRecord(Me.RecordVolunteerID, Me.RecordVOrganizationID, Me.RecordType, Me.ChangeRecordControl1.Reason)
        MyObj.ShowMessage("儲存成功!")
    End Sub

    Protected Sub btnSetGroup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSetGroup.Click
        If Me.ddlVOrganizationID.SelectedValue <> "" Then
            Me.GroupControl1.VOrganizationID = Me.ddlVOrganizationID.SelectedValue
            Me.GroupControl1.InitAndShow()
        Else
            MyObj.ShowMessage("請選擇志工隊!")
        End If
    End Sub
    Protected Sub GroupControl1_OK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GroupControl1.OK_Click
        Me.BindDDLGroupName(Me.VOrganizationID)
        Me.BindGV()
    End Sub

    Protected Sub btnPersonToGroup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPersonToGroup.Click


        Dim dat As New clsData
        Dim sql As New MyStringBuilder


        Using scope As New Transactions.TransactionScope

            sql.Length = 0
            For Each VolunteerID As String In Me.VolunteerSelectedValues
                If IsExistGroup(VolunteerID) = False Then
                    sql.AppendFormat("Insert Into GroupVolunteerMapping(VolunteerID,GroupID,CreateDate,CreateBy) ")
                    sql.AppendFormat("Select '{0}' ", VolunteerID)
                    sql.AppendFormat(",'{0}' ", Me.ddlGroupName.SelectedValue)
                    sql.AppendFormat(", getdate() ")
                    sql.AppendFormat(",'{0}'; ", clsAuth.GetUserID())
                Else
                    sql.AppendFormat("Update GroupVolunteerMapping Set ")
                    sql.AppendFormat("GroupID='{0}', ", Me.ddlGroupName.SelectedValue)
                    sql.AppendFormat("UpdateDate=getdate(), ")
                    sql.AppendFormat("UpdateBy='{0}' ", clsAuth.GetUserID())
                    sql.AppendFormat("where VolunteerID='{0}'; ", VolunteerID)
                End If
            Next

            ' MyObj.WriteLog(sql.ToString())
            If sql.Length <> 0 Then
                dat.AccData(sql)
            End If

            scope.Complete()

        End Using
        Me.BindGV()
        MyObj.ShowMessage("更新成功!")
    End Sub

    Protected Sub btnClearGroup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClearGroup.Click
        If Me.ddlVOrganizationID.SelectedValue <> "" Then
            Dim dat As New clsData
            Dim sql As New MyStringBuilder

            sql.Length = 0
            sql.AppendFormat("delete  from GroupVolunteerMapping ")
            sql.AppendFormat("where VolunteerID In ( ")
            sql.AppendFormat(" select VolunteerID from GroupVolunteerMapping gvm ")
            sql.AppendFormat(" inner join GroupVOrganizationMapping gvo on gvm.GroupID=gvo.GroupID ")
            sql.AppendFormat(" where gvo.VOrganizationID={0}) ", Me.ddlVOrganizationID.SelectedValue)
            Try
                dat.AccData(sql)
                MyObj.ShowMessage("清除成功!")
                Me.BindGV()
            Catch ex As Exception
                MyObj.ShowMessage("清除失敗!")
            End Try
        Else
            MyObj.ShowMessage("請選擇志工隊!")
        End If
    End Sub
End Class

Partial Class WebForm_ManageVolunteer_SearchVolunteer
#Region "方法"
    '初始
    Public Sub InitData(ByVal intVOrganizationID As Integer)
        ddlVOrganizationID.SelectedValue = intVOrganizationID
        SearchRegionVolunteerControl1.VOrganizationID = intVOrganizationID
        If Me.CanAdmin = False Then
     
            If Me.ddlVOrganizationID.SelectedValue <> "" AndAlso CanEdit = True Then
                If MyObj.VolunteerBasicDataIsCheck(ddlVOrganizationID.SelectedValue) = True Then
                    btnShowPerson.Visible = False
                    IsLock = True
                Else
                    btnShowPerson.Visible = True
                    IsLock = False
                End If
            Else
                btnShowPerson.Visible = True
                IsLock = False

            End If

        End If
        Me.BindGV()
        Me.BindDDLGroupName(intVOrganizationID)
    End Sub
    '加入志工存值
    Private Function SavePerson() As Boolean

        If ddlVOrganizationID.SelectedValue <> "" Then

            Dim dat As New clsData
            Dim sql As New MyStringBuilder

            '超過50人
            sql.Length = 0
            sql.AppendFormat("select count(*) from VolunteerView ")
            sql.AppendFormat("where VOrganizationID = {0} ", ddlVOrganizationID.SelectedValue)

            If dat.GetData(sql).Rows(0)(0) > Integer.Parse(MyObj.GetParameter("VOrganization", "VolunteerCount")) Then
                MyObj.ShowMessage("已超過人數限制")
                Return False
            End If

            Using scope As New Transactions.TransactionScope

                sql.Length = 0

                For Each VolunteerID As String In Me.SearchRegionVolunteerControl1.SelectedValues

                    sql.AppendFormat("INSERT VOrganizationMapping (VolunteerID,VOrganizationID,EffectDate) ")
                    sql.AppendFormat("SELECT '{0}'", VolunteerID)
                    sql.AppendFormat(", '{0}'", ddlVOrganizationID.SelectedValue)
                    sql.AppendFormat(", '9999/12/31'; ")

                Next

                If sql.Length <> 0 Then
                    dat.AccData(sql)
                End If

                scope.Complete()

            End Using

            Return True

        End If

    End Function
    '檢查該志工是否存在小組
    Private Function IsExistGroup(ByVal VolunteerID As String)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0
        sql.AppendFormat("Select VolunteerID from GroupVolunteerMapping ")
        sql.AppendFormat("where VolunteerID ='{0}' ", VolunteerID)

        If dat.GetData(sql).Rows.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub Export()
        IsExport = True
        Dim gv As New GridView
        gv.AutoGenerateColumns = False
        gv.Page = Me.Page


        MyObj.AddBoundField(gv, "VolunteerDistinctName", "姓名")
        MyObj.AddBoundField(gv, "VOrganizationName", "志工隊")
        MyObj.AddBoundField(gv, "VolunteerTypeText", "職務")

        Me.BindGV(gv)

        MyObj.ExportToExcel(gv, "VolunteerList.xls")
    End Sub
    Private Function SaveData(ByVal rowIndex As Integer) As Boolean
        Dim row As GridViewRow = Me.gv.Rows(rowIndex)
        Dim key As DataKey = Me.gv.DataKeys(rowIndex)
        Dim volunteerType As String = TryCast(row.FindControl("ddlVolunteerType"), DropDownList).SelectedValue

        Return Me.SaveData(rowIndex, volunteerType)
    End Function

    Private Function SaveData(ByVal rowIndex As Integer, ByVal volunteerType As String) As Boolean
        Select Case volunteerType
            Case "VolunteerLeader"
                Return Me.SetVolunteerType(rowIndex)
            Case "ViceVolunteerLeader"
                Return Me.SetVolunteerType(rowIndex)
            Case "Secretary"
                Return Me.SetVolunteerType(rowIndex)
            Case "Volunteer"
                Return Me.SetAsVolunteer(rowIndex)
        End Select
    End Function
    '設為幹部
    Private Function SetVolunteerType(ByVal rowIndex As Integer) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        Dim row As GridViewRow = Me.gv.Rows(rowIndex)
        Dim key As DataKey = Me.gv.DataKeys(rowIndex)


        sql.Length = 0
        sql.AppendFormat("select COUNT(*) from OtherOrganizationMapping ")
        sql.AppendFormat("where Source = '{0}' ", TryCast(row.FindControl("ddlVolunteerType"), DropDownList).SelectedValue)
        sql.AppendFormat("and UOrganizationID = '{0}' ", key("UOrganizationID"))

        If dat.GetSingleData(sql.ToString(), Nothing, Data.CommandType.Text) >= Int32.Parse(MyObj.GetParameter("OtherOrganizationMapping", TryCast(row.FindControl("ddlVolunteerType"), DropDownList).SelectedValue & "Count")) Then
            MyObj.ShowMessage("已有{0}人擔任 {1} ", Int32.Parse(MyObj.GetParameter("OtherOrganizationMapping", TryCast(row.FindControl("ddlVolunteerType"), DropDownList).SelectedValue & "Count")), TryCast(row.FindControl("ddlVolunteerType"), DropDownList).SelectedItem.Text)
            Me.BindGV()
            Return False
        End If

        Using scope As New Transactions.TransactionScope
            Me.SetAsVolunteer(rowIndex)

            sql.Length = 0
            sql.AppendFormat("insert OtherOrganizationMapping (UserID,UOrganizationID,Source,AuthName) select ")
            sql.AppendFormat(" '{0}' ", key("VolunteerID"))
            sql.AppendFormat(",'{0}' ", key("UOrganizationID"))
            sql.AppendFormat(",'{0}' ", TryCast(row.FindControl("ddlVolunteerType"), DropDownList).SelectedValue)
            sql.AppendFormat(",'{0}' ", "Admin")

            dat.AccData(sql)

            scope.Complete()
        End Using

        Me.ChangeRecordControl1.InitAndShow()
        Me.RecordType = "AddPosition"
        Me.RecordVolunteerID = key("VolunteerID").ToString()
        Me.RecordVOrganizationID = key("UOrganizationID").ToString.Split(",")(1)
        Return True
    End Function
    '設為一般志工
    Private Function SetAsVolunteer(ByVal rowIndex As Integer) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        Dim row As GridViewRow = Me.gv.Rows(rowIndex)
        Dim key As DataKey = Me.gv.DataKeys(rowIndex)

        Using scope As New Transactions.TransactionScope
            sql.Length = 0
            sql.AppendFormat("Select * from OtherOrganizationMapping where Source in ( 'VolunteerLeader', 'ViceVolunteerLeader', 'Secretary' ) ")
            sql.AppendFormat("and UserID = '{0}' ", key("VolunteerID"))
            sql.AppendFormat("and UOrganizationID = '{0}' ", key("UOrganizationID"))

            If dat.GetData(sql).Rows.Count > 0 Then


                sql.Length = 0
                sql.AppendFormat("delete OtherOrganizationMapping where Source in ( 'VolunteerLeader', 'ViceVolunteerLeader', 'Secretary' ) ")
                sql.AppendFormat("and UserID = '{0}' ", key("VolunteerID"))
                sql.AppendFormat("and UOrganizationID = '{0}' ", key("UOrganizationID"))

                dat.AccData(sql)

                Me.ChangeRecordControl1.InitAndShow()
                Me.RecordType = "QuitPosition"
                Me.RecordVolunteerID = key("VolunteerID").ToString()
                Me.RecordVOrganizationID = key("UOrganizationID").ToString().Split(",")(1)
            End If

            scope.Complete()
        End Using

        Return True
    End Function
#End Region

#Region "繫結資料"
    Private Sub BindDDLGroupName(ByVal VOrganizationID As Integer)

        Me.ddlGroupName.DataTextField = "GroupName"
        Me.ddlGroupName.DataValueField = "GroupID"

        Me.ddlGroupName.DataSource = MyObj.GetGroup(VOrganizationID)
        Me.ddlGroupName.DataBind()

    End Sub

    Private Sub BindDDLVOrganizationID()
        Me.ddlVOrganizationID.DataTextField = "VOrganizationName"
        Me.ddlVOrganizationID.DataValueField = "VOrganizationID"
        Me.ddlVOrganizationID.DataSource = MyObj.GetDDLVOrganizationData()
        Me.ddlVOrganizationID.DataBind()

        If Me.ddlVOrganizationID.Items.Count > 1 Then
            Me.ddlVOrganizationID.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())
        End If

    End Sub

    Public Sub BindGV()
        Me.BindGV(Me.gv)
    End Sub

    Public Sub BindGV(ByVal gv As GridView)
        If IsExport = False Then
            If CanQuery = True AndAlso CanAdmin = False Then
                gv.Columns(6).Visible = False
            End If

            If (CanEdit = True Or CanQuery = True) AndAlso CanAdmin = False Then
                If IsLock = True Then
                    gv.Columns(8).Visible = False
                Else
                    gv.Columns(8).Visible = True
                End If
            End If
        End If
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select A.VolunteerID,A.VOrganizationID,A.UOrganizationID,A.PhotoPath,A.Active, VolunteerDistinctName = Case when A.Active='2' then A.VolunteerName+'(儲)' else A.VolunteerName end ")
        sql.AppendFormat(",B.VOrganizationName  ")
        sql.AppendFormat(",case when isnull(C.UserID,'') = '' then 'N' else 'Y' end as IsLeader ")
        sql.AppendFormat(",C.Source, cm_VolunteerType.Text as VolunteerTypeText,vi.EndDate as InsuranceEndDate ")
        sql.AppendFormat(",g.GroupName ")
        sql.AppendFormat("from VolunteerView A ")
        '  sql.AppendFormat("inner join VolunteerDistinctView v on A.VolunteerID = v.VolunteerID ")
        sql.AppendFormat("inner join VOrganizationViewV2 B on A.VOrganizationID = B.VOrganizationID ")
        sql.AppendFormat("left join OtherOrganizationMapping C on A.VolunteerID = C.UserID and C.Source in ( 'VolunteerLeader', 'ViceVolunteerLeader', 'Secretary' ) and C.UOrganizationID = '-1'+','+cast(B.VOrganizationID as nvarchar(50)) ")
        sql.AppendFormat("left join CodeMapping cm_VolunteerType on cm_VolunteerType.Value = case when isnull(C.Source,'')='' then 'Volunteer' else C.Source end and cm_VolunteerType.TableName = 'Volunteer' and cm_VolunteerType.ColumnName = 'VolunteerType' ")
        sql.AppendFormat("left join VolunteerInsurance vi on A.VolunteerID = vi.VolunteerID ")
        sql.AppendFormat("left join GroupVolunteerMapping gvm on A.VolunteerID=gvm.VolunteerID ")
        sql.AppendFormat("left join GroupVOrganizationMapping g on gvm.GroupID=g.GroupID ")

        sql.AppendFormat("WHERE 1=1 ")

        If Me.ddlVOrganizationID.SelectedValue <> "" Then
            sql.AppendFormat("AND B.VOrganizationID='{0}' ", Me.ddlVOrganizationID.SelectedValue)
        End If

        sql.AppendFormat("AND (A.VolunteerId = '{0}' or '{0}'='') ", txtVolunteerId.Text.Replace("'", "''"))
        If Me.txtVolunteerName.Text <> "" Then
            sql.AppendFormat("AND ltrim(replace(replace(A.VolunteerName, '  ', ''), ' ', '')) like '%{0}%'  ", LTrim(Me.txtVolunteerName.Text.Replace("'", "''").Replace("  ", "").Replace(" ", "")))
        End If
        sql.AppendFormat("AND (((A.MobilePhone like '%{0}%' or '{0}'='') or (A.OfficePhone like '%{0}%' or '{0}'=''))) ", txtTEL.Text.Replace("'", "''"))

        If Me.ddlVolunteerType.SelectedValue = "Volunteer" Then
            sql.AppendFormat("AND C.Source is null ")
        ElseIf Me.ddlVolunteerType.SelectedValue <> "" Then
            sql.AppendFormat("AND C.Source = '{0}' ", Me.ddlVolunteerType.SelectedValue)
        End If

        If (Me.CanEdit = True OrElse Me.CanQuery = True) AndAlso Me.CanAdmin = False AndAlso Me.ddlVOrganizationID.SelectedValue = "" Then
            sql.AppendFormat("and B.DirectUOrganizationID in (Select UOrganizationID From AdminVorganizationView where UserID='{0}' )  ", clsAuth.GetUserID())
        End If
        sql.AppendFormat(Me.gv.OrderBySQL)
        'MyObj.WriteErrorLog(sql.ToString)
        dt = dat.GetData(sql)
        gv.DataSource = dt
        gv.DataBind()


    End Sub
    Private VolunteerTypeList As Data.DataTable

    Private Sub BindDDLVolunteerType(ByVal ddl As DropDownList)
        If Me.VolunteerTypeList Is Nothing Then
            Me.VolunteerTypeList = MyObj.GetCodeMappingData("Volunteer", "VolunteerType")
        End If

        Dim dv As Data.DataView = New Data.DataView(Me.VolunteerTypeList)

        '非正式志工無法擔任職務
        If TryCast(ddl.NamingContainer, GridViewRow) IsNot Nothing AndAlso _
            DataBinder.Eval(TryCast(ddl.NamingContainer, GridViewRow).DataItem, "Active").ToString() <> My.VolunteerStatus.VBooked Then
            dv.RowFilter = "Value='Volunteer'"
        End If

        ddl.DataTextField = "Text"
        ddl.DataValueField = "Value"
        ddl.DataSource = dv
        ddl.DataBind()

    End Sub
#End Region

#Region "屬性"
    Public Property IsExport() As Boolean
        Get
            If ViewState("IsExport") Is Nothing Then
                ViewState("IsExport") = False
            End If
            Return ViewState("IsExport")
        End Get
        Set(ByVal value As Boolean)
            ViewState("IsExport") = value
        End Set
    End Property
    Public Property VolunteerID() As String
        Get
            Return ViewState("VolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("VolunteerID") = value
        End Set
    End Property

    Public Property IsLock() As Boolean
        Get
            If ViewState("IsLock") Is Nothing Then
                ViewState("IsLock") = False
            End If
            Return ViewState("IsLock")
        End Get
        Set(ByVal value As Boolean)
            ViewState("IsLock") = value
        End Set
    End Property


    Public ReadOnly Property PhotoPathBase() As String
        Get
            If ViewState("PhotoPathBase") Is Nothing Then
                ViewState("PhotoPathBase") = MyObj.GetFilePath("VolunteerPhoto")
            End If

            Return ViewState("PhotoPathBase")
        End Get
    End Property
    Public Property VOrganizationID() As String
        Get
            If Me.gv.SelectedRow Is Nothing Then
                ViewState("VOrganizationID") = Me.gv.DataKeys(0)("VOrganizationID")
            Else
                ViewState("VOrganizationID") = Me.gv.DataKeys(Me.gv.SelectedRow.RowIndex)("VOrganizationID")
            End If
            Return ViewState("VOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("VOrganizationID") = value

        End Set
    End Property
    Public Property RecordVOrganizationID() As String
        Get
            Return ViewState("RecordVOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("RecordVOrganizationID") = value
        End Set
    End Property
    Public Property RecordVolunteerID() As String
        Get
            Return ViewState("RecordVolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("RecordVolunteerID") = value
        End Set
    End Property
    Public Property RecordType() As String
        Get
            Return ViewState("RecordType")
        End Get
        Set(ByVal value As String)
            ViewState("RecordType") = value
        End Set
    End Property
    Public ReadOnly Property VolunteerSelectedValues() As List(Of String)
        Get
            Dim Volunteers As New List(Of String)

            For Each row As GridViewRow In Me.gv.Rows
                Dim key As DataKey = Me.gv.DataKeys(row.RowIndex)

                If TryCast(row.FindControl("chkGroup"), CheckBox).Checked = True Then
                    Volunteers.Add(key("VolunteerID"))
                End If
            Next

            Return Volunteers
        End Get
    End Property
#End Region

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)


End Class